{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# This is for making changes on the fly\n",
    "\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%pylab inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from Centerline import Centerline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "npoints = 10\n",
    "x = np.arange(npoints)*2*np.pi/npoints\n",
    "y = np.sin(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cl = Centerline(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x0 = x[5]*0.5 + x[6]*0.5\n",
    "y0 = np.sin(x0) + 0.2\n",
    "x1 = x0\n",
    "y1 = np.sin(x0) - 0.2\n",
    "\n",
    "xx = [x0,x1]\n",
    "yy = [y0,y1]\n",
    "\n",
    "i,d,xcl,ycl,s,n = cl(xx,yy)\n",
    "\n",
    "print(i,d,s,n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(x,y,'o')\n",
    "plot(xx,yy,'rx')\n",
    "plot(xcl,ycl,'ro')\n",
    "plot(x[i],y[i],'gx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cl2 = Centerline(x,y,ds=0.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "i,d,xcl,ycl,s,n = cl2(xx,yy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(cl2.x,cl2.y,'o')\n",
    "plot(xx,yy,'rx')\n",
    "plot(xcl,ycl,'ro')\n",
    "plot(cl2.x[i],cl2.y[i],'gx')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Test the centerline with an observation and resampling"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "width = 0.5 + 0.25*y\n",
    "clw = Centerline(x,y,obs=[width],obs_names=['width'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(clw.x,clw.y,'o')\n",
    "plot(clw.x,clw.y+clw.width,'-k',alpha=0.5)\n",
    "plot(clw.x,clw.y-clw.width,'-k',alpha=0.5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "width = 0.5 + 0.25*y\n",
    "clw2 = Centerline(x,y,ds=0.1,obs=[width],obs_names=['width'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(clw2.x,clw2.y,'o')\n",
    "plot(clw2.x,clw2.y+clw2.width,'-k',alpha=0.5)\n",
    "plot(clw2.x,clw2.y-clw2.width,'-k',alpha=0.5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
